package com.jianguozh.com.difs.generator;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.jianguozh.difs.framework.base.BaseController;
import com.jianguozh.difs.framework.base.BaseEntity;

import java.sql.SQLException;
import java.util.Collections;

/**
 * mybatis plus 代码生成器
 *
 * @author hanrs
 * @email 4076130@qq.com
 * @since 2022/3/22 14:04
 */
public class CodeGenerator {


    /**
     * 使用select GROUP_CONCAT(TABLE_NAME)  from information_schema.TABLES WHERE TABLE_SCHEMA ='difs'
     * 查询表名
     */
//    private static final String module_support_system_tables = "sup_catering,sup_client,sup_corporate,sup_res,sup_role,sup_supplier,sup_user";
//    private static final String module_support_ops_tables = "sup_app_version,sup_param,sup_zone";
    private static final String module_support_staff_tables = "edu_chapter,edu_course";

    /**
     * 执行 run
     */
    public static void main(String[] args) throws SQLException {
        FastAutoGenerator.create("jdbc:mysql://192.168.30.249:3306/edu_online", "root", "nut123")
                .globalConfig(builder -> {
                    builder.author("hanrs") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("D://"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.jianguozh.eduonline.srv") // 设置父包名
                            .moduleName("module") // 设置父包模块名
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude(module_support_staff_tables.split(",")) // 设置需要生成的表名
                            .addTablePrefix("edu_") // 设置过滤表前缀
                            .controllerBuilder().superClass(BaseController.class)
                            .enableRestStyle()
                            .entityBuilder().superClass(BaseEntity.class)
                            .enableChainModel()
                            .enableLombok()
                            .enableRemoveIsPrefix();

                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();

    }

}
